package com.settlement.system.service.impl;

import com.settlement.system.mapper.BaseMapper;
import com.settlement.system.mapper.TblRrVoucherTypeMapper;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.TblRrVoucherType;
import com.settlement.system.service.ITblRrVoucherTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * 收退款-凭证类型 服务实现类
 * @author Ximi
 * @since 2020-07-06
 */
@Slf4j
@Service
public class TblRrVoucherTypeServiceImpl extends BaseServiceImpl implements ITblRrVoucherTypeService {

    @Resource
    private TblRrVoucherTypeMapper tblRrVoucherTypeMapper;

    @Override
    public BaseMapper init() {
        return tblRrVoucherTypeMapper;
    }

    @Override
    public TblRrVoucherType getByVoucherType(String voucherType) throws ServiceException {
        try {
            return tblRrVoucherTypeMapper.getByVoucherType(voucherType,null);
        } catch (Exception ex){
            log.error("getByVoucherType exception",ex);
            throw new ServiceException("getByVoucherType exception",ex);
        }
    }

    @Override
    public TblRrVoucherType getBySort(String sort) throws ServiceException {
        try {
            return tblRrVoucherTypeMapper.getBySort(sort);
        } catch (Exception ex){
            log.error("getBySort exception",ex);
            throw new ServiceException("getBySort exception",ex);
        }
    }

    @Override
    public TblRrVoucherType getByVoucherTypeAndNotShareOrNot(String voucherType, String shareOrNot) throws ServiceException {
        try {
            return tblRrVoucherTypeMapper.getByVoucherTypeAndNotShareOrNot(voucherType,shareOrNot);
        } catch (Exception ex){
            log.error("getByVoucherTypeAndNotShareOrNot exception",ex);
            throw new ServiceException("getByVoucherTypeAndNotShareOrNot exception",ex);
        }
    }

    @Override
    public TblRrVoucherType getByVoucherTypeAndNotBeforeOrAfterTicket(String voucherType, String beforeOrAfterTicket) throws ServiceException {
        try {
            return tblRrVoucherTypeMapper.getByVoucherTypeAndNotBeforeOrAfterTicket(voucherType,beforeOrAfterTicket);
        } catch (Exception ex){
            log.error("getByVoucherTypeAndNotBeforeOrAfterTicket exception",ex);
            throw new ServiceException("getByVoucherTypeAndNotBeforeOrAfterTicket exception",ex);
        }
    }

    @Override
    public List<TblRrVoucherType> selectByParams(TblRrVoucherType tblRrVoucherType) throws ServiceException{
        try {
            return tblRrVoucherTypeMapper.selectByParams(tblRrVoucherType);
        } catch (Exception ex){
            log.error("selectByParams by tblRrVoucherType happen exception",ex);
            throw new ServiceException("selectByParams by tblRrVoucherType happen exception",ex);
        }
    }

    @Override
    public String getShareOrNot(String voucherType) throws ServiceException {
        return getShareOrNotByVoucherType(voucherType);
    }

    @Override
    public String getBeforeOrAfterTicket(String voucherType) throws ServiceException {
        return getBeforeOrAfterTicketByVoucherType(voucherType);
    }

    private String getShareOrNotByVoucherType(String voucherType) throws ServiceException {
        try {
            return tblRrVoucherTypeMapper.getShareOrNotByVoucherType(voucherType);
        } catch (Exception ex) {
            log.error("getShareOrNotByVoucherType exception", ex);
            throw new ServiceException("getShareOrNotByVoucherType exception", ex);
        }
    }

    private String getBeforeOrAfterTicketByVoucherType(String voucherType) throws ServiceException {
        try {
            return tblRrVoucherTypeMapper.getBeforeOrAfterTicketByVoucherType(voucherType);
        } catch (Exception ex) {
            log.error("getShareOrNotByVoucherType exception", ex);
            throw new ServiceException("getShareOrNotByVoucherType exception", ex);
        }
    }

}

